<!DOCTYPE html>
<html lang="en-us">
<head><head>
    <meta name="referrer" content="no-referrer"/>
    <meta name="google-site-verification" content="9vIieCe-Qpd78QOmBl63rGtIVbhY6sYyuxX3j8XWBA4" />
    <meta name="baidu-site-verification" content="LRrmH41lz7" />
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <meta name="description" content="npm使用技巧">
    
    <meta name="keyword"  content="暴走的初号机, shinji3887, 暴走的初号机的网络日志, 暴走的初号机的博客, shinji3887 Blog, 博客, 个人网站, 互联网, Web, 云原生, PaaS, Istio, Kubernetes, 微服务, Microservice">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <title>linux下使用npm install报EACCES的解决方法-同步率400%</title>

    <link rel="canonical" href="/post/linux-npm-install-eacces/">

    <link rel="stylesheet" href="https://lupeier.cn-sh2.ufileos.com/iDisqus.min.css"/>
	
    
    <link rel="stylesheet" href="https://lupeier.cn-sh2.ufileos.com/bootstrap.min.css">

    
    <link rel="stylesheet" href="https://lupeier.cn-sh2.ufileos.com/hux-blog.min.css">

    
    <link rel="stylesheet" href="https://lupeier.cn-sh2.ufileos.com/syntax.css">

    
    <link rel="stylesheet" href="https://lupeier.cn-sh2.ufileos.com/zanshang.css">

    
    <link href="/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    
    
    <script src="https://lupeier.cn-sh2.ufileos.com/jquery.min.js"></script>
    
    
    <script src="https://lupeier.cn-sh2.ufileos.com/bootstrap.min.js"></script>
    
    
    <script src="https://lupeier.cn-sh2.ufileos.com/hux-blog.min.js"></script>
</head>
</head>

<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">L&#39;s Blog</a>
        </div>

        
        
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/">Home</a>
                    </li>
                    
                    <li>
                        <a href="categories/tech">tech</a>
                    </li>
                    
                    <li>
                        <a href="categories/tips">tips</a>
                    </li>
                    
                    <li>
                        <a href="/about">About</a>
                    </li>
                    
                </ul>
            </div>
        </div>
        
    </div>
    
</nav>
<script>
    
    
    
    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        
            $navbar.className = " ";
            
            setTimeout(function(){
                
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>




<style type="text/css">
    header.intro-header{
        background-image: url('https://lupeier.cn-sh2.ufileos.com/clouds-dawn-dock-891822.jpg')
    }
</style>
<header class="intro-header" >
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <div class="tags">
                       
                       <a class="tag" href="/tags/npm" title="npm">
                           npm
                        </a>
                        
                    </div>
                    <h1>linux下使用npm install报EACCES的解决方法</h1>
                    <h2 class="subheading"></h2>
                    <span  class="meta">Posted by L&#39; on Wednesday, November 21, 2018
                        
                    </span>
					<br>
                </div>
            </div>
        </div>
    </div>
</header>




<article>
    <div class="container">
        <div class="row">

            
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                post-container">

        		
                        <header>
                        <h2>TOC</h2>
                        </header>
                        <nav id="TableOfContents"></nav>
        		
        		<p>前端项目需要进行CI/CD集成，CI服务器是linux版本的，所以需要在服务器上安装npm环境，记录一下安装过程以及碰到的坑。安装很简单，直接下载官网的<a href="https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz">linux二进制包</a>，并将bin目录设置在环境变量中就ok了，执行</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#f92672">[</span>root@localhost dist<span style="color:#f92672">]</span><span style="color:#75715e"># npm -version</span>
6.4.1
</code></pre></div><p>说明安装成功了，接下来在执行项目的初始化（基于vue-cli）npm install时，却反复提示权限不足</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash"><span style="color:#f92672">[</span>root@localhost bocsh-vue-admin<span style="color:#f92672">]</span><span style="color:#75715e"># npm install</span>

&gt; nodent-runtime@3.2.1 install /home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime
&gt; node build.js

fs.js:115
    throw err;
    ^

Error: EACCES: permission denied, open <span style="color:#e6db74">&#39;/home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime/dist/index.js&#39;</span>
    at Object.openSync <span style="color:#f92672">(</span>fs.js:436:3<span style="color:#f92672">)</span>
    at Object.writeFileSync <span style="color:#f92672">(</span>fs.js:1187:35<span style="color:#f92672">)</span>
    at Object.&lt;anonymous&gt; <span style="color:#f92672">(</span>/home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime/build.js:5:4<span style="color:#f92672">)</span>
    at Module._compile <span style="color:#f92672">(</span>internal/modules/cjs/loader.js:688:30<span style="color:#f92672">)</span>
    at Object.Module._extensions..js <span style="color:#f92672">(</span>internal/modules/cjs/loader.js:699:10<span style="color:#f92672">)</span>
    at Module.load <span style="color:#f92672">(</span>internal/modules/cjs/loader.js:598:32<span style="color:#f92672">)</span>
    at tryModuleLoad <span style="color:#f92672">(</span>internal/modules/cjs/loader.js:537:12<span style="color:#f92672">)</span>
    at Function.Module._load <span style="color:#f92672">(</span>internal/modules/cjs/loader.js:529:3<span style="color:#f92672">)</span>
    at Function.Module.runMain <span style="color:#f92672">(</span>internal/modules/cjs/loader.js:741:12<span style="color:#f92672">)</span>
    at startup <span style="color:#f92672">(</span>internal/bootstrap/node.js:285:19<span style="color:#f92672">)</span>
npm WARN ajv-errors@1.0.0 requires a peer of ajv@&gt;<span style="color:#f92672">=</span>5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-config-standard@12.0.0-alpha.0 requires a peer of eslint@&gt;<span style="color:#f92672">=</span>5.0.0-alpha.2 but none is installed. You must install peer dependencies yourself.
npm WARN bocsh-vue-admin@2.1.0 No repository field.
npm WARN bocsh-vue-admin@2.1.0 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 <span style="color:#f92672">(</span>node_modules/fsevents<span style="color:#f92672">)</span>:
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform <span style="color:#66d9ef">for</span> fsevents@1.2.4: wanted <span style="color:#f92672">{</span><span style="color:#e6db74">&#34;os&#34;</span>:<span style="color:#e6db74">&#34;darwin&#34;</span>,<span style="color:#e6db74">&#34;arch&#34;</span>:<span style="color:#e6db74">&#34;any&#34;</span><span style="color:#f92672">}</span> <span style="color:#f92672">(</span>current: <span style="color:#f92672">{</span><span style="color:#e6db74">&#34;os&#34;</span>:<span style="color:#e6db74">&#34;linux&#34;</span>,<span style="color:#e6db74">&#34;arch&#34;</span>:<span style="color:#e6db74">&#34;x64&#34;</span><span style="color:#f92672">})</span>

npm ERR! code ELIFECYCLE
npm ERR! errno <span style="color:#ae81ff">1</span>
npm ERR! nodent-runtime@3.2.1 install: <span style="color:#e6db74">`</span>node build.js<span style="color:#e6db74">`</span>
npm ERR! Exit status <span style="color:#ae81ff">1</span>
npm ERR!
npm ERR! Failed at the nodent-runtime@3.2.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
</code></pre></div><p>这里百思不得其解，谷歌了半天，还是官网的一篇文章解决问题，就是更换npm的默认存储库（至于为什么换了就好了，也不明白，我是root用户啊。。），步骤如下：</p>
<ol>
<li>
<p>Back up your computer.</p>
</li>
<li>
<p>On the command line, in your home directory, create a directory for global installations:</p>
</li>
</ol>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">mkdir ~/.npm-global
</code></pre></div><ol>
<li>Configure npm to use the new directory path:</li>
</ol>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">npm config set prefix <span style="color:#e6db74">&#39;~/.npm-global&#39;</span>
</code></pre></div><ol>
<li>In your preferred text editor, open or create a ~/.profile file and add this line:</li>
</ol>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">export PATH<span style="color:#f92672">=</span>~/.npm-global/bin:$PATH
</code></pre></div><ol>
<li>On the command line, update your system variables:</li>
</ol>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">source ~/.profile
</code></pre></div><ol>
<li>To test your new configuration, install a package globally without using sudo:</li>
</ol>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">npm install -g jshint
</code></pre></div><p>重新安装package顺利下载。
总结：其实也没啥好总结的，碰到问题多看官网多看英文文档（能谷歌最好），一般都比较靠谱。</p>
<p><a href="https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally">官网文章链接</a></p>

        
                
        
              <hr>
              <ul class="pager">
                  
                  <li class="previous">
                      <a href="/post/docker-kubernetes-commands/" data-toggle="tooltip" data-placement="top" title="docker与kubernetes常用命令集合">&larr; Previous Post</a>
                  </li>
                  
                  
                  <li class="next">
                      <a href="/post/github-flow-practice/" data-toggle="tooltip" data-placement="top" title="Git的代码分支策略实践">Next Post &rarr;</a>
                  </li>
                  
              </ul>
  
              

<div id="gitalk-container"></div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script src="/js/md5.min.js"></script>
<script>
	const gitalk = new Gitalk({
	  clientID: 'aff2580d8cc58af83367',
	  clientSecret: '747547f5f87fcc5145b847ab76a498d7e501319f',
	  repo: 'comment',
	  owner: 'shinji3887',
	  admin: ['shinji3887'],
	  id: md5(location.pathname),      
	  distractionFreeMode: false  
	})

	gitalk.render('gitalk-container')
</script>


            </div>
            
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                
                <section>
                    <hr class="hidden-sm hidden-xs">
                    <h5><a href="/tags/">FEATURED TAGS</a></h5>
                    <div class="tags">
                     
                    
                        
                            <a href="/tags/api-gateway" title="api-gateway">
                                api-gateway
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/cloud-native" title="cloud-native">
                                cloud-native
                            </a>
                        
                    
                        
                            <a href="/tags/devops" title="devops">
                                devops
                            </a>
                        
                    
                        
                            <a href="/tags/docker" title="docker">
                                docker
                            </a>
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/istio" title="istio">
                                istio
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/kubernetes" title="kubernetes">
                                kubernetes
                            </a>
                        
                    
                        
                            <a href="/tags/microservice" title="microservice">
                                microservice
                            </a>
                        
                    
                        
                    
                        
                    
                        
                    
                        
                    
                        
                            <a href="/tags/restful" title="restful">
                                restful
                            </a>
                        
                    
                        
                    
                        
                            <a href="/tags/servicemesh" title="servicemesh">
                                servicemesh
                            </a>
                        
                    
                        
                            <a href="/tags/spring-cloud" title="spring-cloud">
                                spring-cloud
                            </a>
                        
                    
                        
                            <a href="/tags/vue" title="vue">
                                vue
                            </a>
                        
                    
                        
                    
                        
                    
                    </div>
                </section>

                
                <hr>
                <h5>FRIENDS</h5>
                <ul class="list-inline">
                    
                        <li><a target="_blank" href="https://skyao.io/">小剑的博客</a></li>
                    
                        <li><a target="_blank" href="https://zhaohuabing.com/">huabing的博客</a></li>
                    
                        <li><a target="_blank" href="http://blog.didispace.com/">程序猿DD的博客</a></li>
                    
                </ul>
            </div>
        </div>
    </div>
</article>




<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                   
                   <li>
                       <a href="" rel="alternate" type="application/rss+xml" title="L&#39;s Blog" >
                           <span class="fa-stack fa-lg">
                               <i class="fa fa-circle fa-stack-2x"></i>
                               <i class="fa fa-rss fa-stack-1x fa-inverse"></i>
                           </span>
                       </a>
                   </li>
                   
                    
                    <li>
                        <a href="mailto:18016380795@163.com">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    
                    
                    
                    
                    

                    

		    
                    
                    <li>
                        <a target="_blank" href="/link%20of%20wechat%20QR%20code%20image">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-wechat fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    
                    
                    <li>
                        <a target="_blank" href="https://github.com/shinji3887">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    
                    
                    <li>
                        <a target="_blank" href="https://www.linkedin.com/in/lupeier">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-linkedin fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
		    
                </ul>
		<p class="copyright text-muted">
                    Copyright &copy; L&#39;s Blog , 2018
                    <br>
                    <br>
                    <a href="http://icp.chinaz.com/info?q=lupeier.com" target="_blank">备案号：沪ICP备19022667号-1</a>                    
                </p>
            </div>
        </div>
    </div>
</footer>



<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>






<script>
    
    if($('#tag_cloud').length !== 0){
        async("/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>


<script>
    async("/js/fastclick.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>


<script>
    (function(){
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https'){
       bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      }
      else{
      bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>







</body>
</html>
